package com.jms.tomcat.mapping;

import java.util.regex.Pattern;

/**
 * 映射类
 * 用于匹配 Servlet 或 Filter
 */
public abstract class JmsMapping <T> {

    /**
     * 实体对象 servlet 或 filter
     */
    protected T object;
    /**
     * 正则匹配规则列表
     */
    protected Pattern pattern;

    public T get() {
        return object;
    }

    public void set(T object) {
        this.object = object;
    }


    /**
     * 正则匹配构造逻辑
     * @param uri uri
     */
    protected Pattern buildPattern(String uri) {
        if (uri.contains("*")) {
            uri = uri.replace("*", ".*");
        }
        return Pattern.compile(uri);
    }

    /**
     * 判断uri是否匹配servlet
     * @param uri uri
     * @return boolean
     */
    public boolean matcher(String uri) {
        return pattern.matcher(uri).matches();
    }
}
